package com.yidu.ladder.delivery.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.ladder.delivery.domain.Cooperation;
import com.yidu.ladder.delivery.domain.CooperationVo;
import com.yidu.ladder.delivery.service.CooperationService;
import com.yidu.ladder.util.ID;

/**
 * 合作网络控制器
 * 
 * @author yy
 * @since 2019-12-20
 *
 */
@Controller
@RequestMapping("/system")
public class CooperationController {

	/**
	 * 关联合作网络业务逻辑层
	 */
	@Autowired
	private CooperationService cooperationService;

	public CooperationService getCooperationService() {
		return cooperationService;
	}

	public void setCooperationService(CooperationService cooperationService) {
		this.cooperationService = cooperationService;
	}

	/**
	 * 管理页面
	 * 
	 * @return 合作网络管理页的URL
	 */
	@RequestMapping(value = "cooperation")
	public String cooperation() {
		return "sys/cooperation";
	}

	/**
	 * 检索合作网络
	 * 
	 * @param cooperationVo 合作网络包装类
	 * @return 合作网络信息数据
	 */
	@ResponseBody
	@RequestMapping(value = "cooperations", method = RequestMethod.GET)
	public Map<String, Object> queryCooperation(CooperationVo cooperationVo) {
		// 执行分页查询角色方法
		Map<String, Object> cooperationMap = cooperationService.queryCooperationByCriteriaWithPage(cooperationVo);
		// 返回结果
		return cooperationMap;
	}

	/**
	 * 添加合作网络
	 * 
	 * @param cooperation 合作网络
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "cooperation", method = RequestMethod.POST)
	public int addCooperation(Cooperation cooperation) {
		cooperation.setCooperationId(ID.getUUID());
		cooperation.setUseable("Y");
		// 执行添加合作网络方法
		int insert = cooperationService.addCooperation(cooperation);
		// 返回结果
		return insert;

	}

	/**
	 * 修改合作网络
	 * 
	 * @param cooperation 合作网络
	 * @return
	 */

	@ResponseBody
	@RequestMapping(value = "cooperation", method = RequestMethod.PUT)
	public boolean updateCooperation(Cooperation cooperation) {
		// 执行修改合作网络方法
		boolean updateCooperation = cooperationService.updateCooperation(cooperation);
		// 返回结果
		return updateCooperation;

	}

	/**
	 * 冻结或还原合作网络
	 * 
	 * @param cooperationId 合作网络Id
	 * @param useable       是否可用
	 * @return
	 */
	@RequestMapping(value = "cooperation", method = RequestMethod.DELETE)

	@ResponseBody
	public boolean frozenOrRecoveCooperation(String cooperationId, String useable) {
		// 执行冻结或还原合作网络方法
		boolean result = cooperationService.frozenOrRecoveCooperation(cooperationId, useable);
		// 返回结果
		return result;
	}

}
